package br.com.lh.urabuilder.util
{
	import br.com.lh.urabuilder.business.ISelectableComponentsManager;
	import br.com.lh.urabuilder.business.ViewManager;
	import br.com.lh.urabuilder.view.ActionComponent;
	
	import mx.collections.ArrayCollection;
	
	/**
	 * Returns the list of all the components in screen 
	 * in a combobox representation.
	 *  
	 * @author Luiz Henrique
	 * 
	 */
	public class SelectableComponentsUtils implements ISelectableComponentsManager
	{
		[Bindable]
		private var _comboComponents:ArrayCollection = null;
		
		private var viewManager:ViewManager;
		
		public function SelectableComponentsUtils(viewManager:ViewManager){
			this.viewManager = viewManager;
			_comboComponents = getSelectableComponents();
		}
		
		public function get comboComponents():ArrayCollection{
			return _comboComponents;
		}
		
		public function getSelectableComponents():ArrayCollection{
			var selectableComponents:ArrayCollection = new ArrayCollection();
			var components:ArrayCollection =viewManager.getComponents();
			for each (var component:ActionComponent in components){
				if (component !=null){
					var ob:Object = new Object();
					ob.data = component.uraAction.getId();
					ob.label = component.textArea.text + " (" + component.uraAction.xmlName() + ")";
					selectableComponents.addItem(ob);
				}	
			}
			return selectableComponents;
		}

		public function updateSelectableList():void{
			_comboComponents = getSelectableComponents();
		}
		
		public function clearUra():void{
			updateSelectableList();
		}
		
	}
}